package cn.whale.basic.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateTimeUtil {

    public static String endTime(Integer plusDays){
        if(plusDays != null){
            LocalDate endDate = LocalDate.now().plusDays(plusDays);
            LocalDateTime end = LocalDateTime.of(LocalDate.now().plusDays(plusDays), LocalTime.MAX);
            return end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        }
        return startTime();
    }

    public static String startTime(){
        LocalDateTime start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }


    public static long endTimeMilli(Integer plusDays){
        if(plusDays != null){
            LocalDate endDate = LocalDate.now().plusDays(plusDays);
            LocalDateTime end = LocalDateTime.of(LocalDate.now().plusDays(plusDays), LocalTime.MAX);
            return end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        }
        return startTimeMilli();
    }

    public static long startTimeMilli(){
        LocalDateTime start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        return start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
    }
    public static Date now(){
        return new Date();
    }
    public static long nowMilli(){
        return new Date().getTime();
    }

}
